#' Roll apply x to real function
#'
#' @param x numeric vector
#' @param period rolling window period
#' @param fx a real function
#' @param fill value to fill
#'
#' @return numeric vector
#' @export
#'
roll_fx <- function(x, period, fx, fill = NA_real_)
{
  ans <- rep(fill, length(x))
  for (i in seq(period, length(x)))
  {
    idx <- seq(i - period + 1, i)
    ans[i] <- fx(x[idx])
  }

  ans
}
